package com.forum.service;


import com.github.benmanes.caffeine.cache.Caffeine;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.concurrent.TimeUnit;

/**
 * @author lbwxxc
 * @date 2025/4/6 12:35
 * @description:
 */
@Configuration
@ComponentScan("com.forum.service")
@MapperScan(basePackages = {
        "com.forum.service.user.mapper"
})
@EnableScheduling
@EnableAsync
public class ForumServiceAutoConfig {

    /**
     * @param:
     * @return: org.springframework.cache.CacheManager
     * @description: 管理缓存过期时间和最大缓存容量
     */
    @Bean("caffeineCacheManager")
    public CacheManager cacheManager() {
        CaffeineCacheManager cacheManager = new CaffeineCacheManager();
        cacheManager.setCaffeine(Caffeine.newBuilder()
                .expireAfterWrite(1, TimeUnit.SECONDS)
                .initialCapacity(100)
                .maximumSize(100)
                );
        return cacheManager;
    }
}
